package com.lovi.mysql_;





import com.mysql.cj.jdbc.Driver;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;

import java.sql.Statement;
import java.util.Properties;

/**
 * jdbc连接到数据库并执行sql
 */
public class Test01 {
    public static void main(String[] args) throws SQLException {

        //驱动
        Driver driver = new Driver();

        String url = "jdbc:mysql://192.168.3.203:3306/loviTest";
        Properties properties = new Properties();
        Connection connect = null;
        properties.put("user", "lovi");
        properties.put("password", "root");
        connect = driver.connect(url, properties);
        Statement statement = connect.createStatement();//执行sql语句
        String sql = "select * from actor;";
        ResultSet resultSet = statement.executeQuery(sql);
        while (resultSet.next()){
            System.out.print(resultSet.getString("name")+"\t");
            System.out.print(resultSet.getString("birthday"));
            System.out.println();
        }
        resultSet.close();
        statement.close();
        connect.close();
    }
}
